﻿using System.Collections.Generic;
using D2D2.Core.Sprite;
using D2D2.SharedInterfaces.Networking;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace D2D2.Core.SpriteManager
{


    public class MonsterManagerClient : BattleSpriteManager
    {
        private List<Monster> _monsters = new List<Monster>();

        public void Update(MonsterObject monsterObject)
        {
            Monster battleMonster = _monsters.Find(m => m.Id == monsterObject.Id);
            battleMonster.AddSnapshot(monsterObject);

            /*
            MonsterObject existMonster = battleMonster.MonsterObject;

            float deltaLive = monsterObject.CurrentLive - existMonster.CurrentLive;

            if (deltaLive < 0)
                battleMonster.DecreaseHit(-deltaLive);

            if (deltaLive > 0)
                battleMonster.IncreaseHit(deltaLive);

            existMonster.CurrentLive = monsterObject.CurrentLive;
            existMonster.Level = monsterObject.Level;
            existMonster.LiveRegen = monsterObject.LiveRegen;
            existMonster.Location = monsterObject.Location;
            existMonster.MaxDamage = monsterObject.MaxDamage;
            existMonster.MinDamage = monsterObject.MinDamage;
            existMonster.TotalLive = monsterObject.TotalLive;
           */
        }

        public void MouseClickHandle(int x, int y)
        {
            foreach (Monster monster in _monsters)
            {
                monster.MouseClickHandle(x, y);
            }
        }

        public  Monster Add(Rectangle location, SpriteType spriteType, MonsterObject monsterObject)
        {
            Monster monster = new Monster(location, spriteType, monsterObject);
            monster.Init(monsterObject.TotalLive);

            _monsters.Add(monster);

            return monster;
        }

        public bool Exist(MonsterObject monsterObject)
        {
            return _monsters.Exists(m => m.Id == monsterObject.Id);
        }

        public override void Update(GameTime gameTime)
        {
            //_monsters = _monsters.FindAll(monster => monster.Alive);

            _monsters.ForEach(m => m.Update(gameTime));
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            _monsters.ForEach(m => m.Draw(spriteBatch));
        }
    }
}
